Skip to content

Conversation

@kumarUjjawal
Copy link
Contributor

@kumarUjjawal kumarUjjawal commented Nov 10, 2025

Pull Request

Related issue

Fixes #660

What does this PR do?

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

Summary by CodeRabbit

  • New Features

    • Filterable attributes now accept either simple attribute names or richer settings with feature modes.
    • Retrieval and update operations support the mixed-syntax representation.
  • Backward Compatibility

    • Existing simple-name workflows continue to work and are automatically mapped to the new format.
  • Documentation / Tests

    • Examples and tests updated to demonstrate mixed-syntax usage.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 10, 2025

Walkthrough

Adds mixed-syntax support for Meilisearch v1.14 filterableAttributes: introduces new public types (FilterableAttribute, FilterableAttributesSettings, FilterFeatures, FilterFeatureModes), changes Settings.filterable_attributes to Option<Vec<FilterableAttribute>>, updates Index get/set methods (advanced variants), and adapts tests and code samples.

Changes

Cohort / File(s) Summary
Core types & Settings
src/settings.rs
Adds FilterableAttribute (untagged enum) plus FilterableAttributesSettings, FilterFeatures, FilterFeatureModes; implements From<String> and From<&str>; changes Settings.filterable_attributes: Option<Vec<FilterableAttribute>>; adds with_filterable_attributes_advanced() and adapts with_filterable_attributes() to wrap strings as FilterableAttribute::Attribute.
Index API methods & requests
src/settings.rs
Adds get_filterable_attributes_advanced() and set_filterable_attributes_advanced(); updates set_filterable_attributes() to accept/serialize Vec<FilterableAttribute> (wraps string inputs for backward compatibility); updates internal request/response types from Vec<String> -> Vec<FilterableAttribute> where applicable.
Tests
src/documents.rs
Updates tests to expect Option<Vec<FilterableAttribute>>, replaces string expectations with FilterableAttribute::Attribute("..."), and adds necessary imports.
Code samples
.code-samples.meilisearch.yaml
Replaces simple list example with mixed-syntax example (plain attribute + settings object), imports meilisearch_sdk::settings types, and uses set_filterable_attributes_advanced in sample usage.

Sequence Diagram(s)

sequenceDiagram
    participant Client as Client Code
    participant Index as Index API
    participant Server as Meilisearch

    rect rgba(135,206,250,0.06)
    Note over Client,Index: Update filterable attributes (mixed syntax)
    Client->>Index: set_filterable_attributes_advanced([ "author", { attributePatterns:[...], features:{...} } ])
    Index->>Server: POST /settings/filterable-attributes  (body: Vec<FilterableAttribute>)
    Server-->>Index: TaskInfo
    Index-->>Client: Result<TaskInfo>
    end

    rect rgba(220,220,220,0.04)
    Note over Client,Index: Backward-compatible string usage
    Client->>Index: set_filterable_attributes(["author","genre"])
    Index->>Index: Wrap strings -> FilterableAttribute::Attribute(...)
    Index->>Server: POST /settings/filterable-attributes  (body: Vec<FilterableAttribute>)
    Server-->>Index: TaskInfo
    Index-->>Client: Result<TaskInfo>
    end

    rect rgba(144,238,144,0.06)
    Note over Client,Index: Retrieve mixed syntax
    Client->>Index: get_filterable_attributes_advanced()
    Index->>Server: GET /settings/filterable-attributes
    Server-->>Index: Vec<FilterableAttribute> (mixed)
    Index-->>Client: Result<Vec<FilterableAttribute>>
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify serde untagged representation and JSON round-tripping for FilterableAttribute.
  • Confirm From<String> / From<&str> conversions and that with_filterable_attributes preserves backward compatibility.
  • Check Index methods and request/response type changes for correct serialization and API endpoints.
  • Review updated tests and code sample wiring/imports.

Suggested reviewers

  • curquiza
  • irevoire

Poem

🐇 I sniffed the types and gave a cheer,
Strings and settings hopping near.
Patterns and features, mixed delight,
Filterable fields now jump in sight.
A tiny hop — the API’s bright.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new filterableAttributes syntax API to the settings module.
Linked Issues check ✅ Passed All three objectives from issue #660 are addressed: accept new filterableAttributes syntax, return it when Meilisearch provides it, and update the code sample.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the filterableAttributes syntax API as required by issue #660.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/settings.rs (1)

1614-1633: Consider more flexible signature for set_filterable_attributes_advanced.

The current signature impl IntoIterator<Item = FilterableAttribute> requires owned values, which prevents passing borrowed slices like &[FilterableAttribute]. This differs from other setter methods (e.g., set_stop_words at line 1497) that use Item = impl AsRef<str> to accept both owned and borrowed values.

While the current design is simpler and works correctly, consider whether accepting borrowed values would improve ergonomics:

pub async fn set_filterable_attributes_advanced(
    &self,
    filterable_attributes: &[FilterableAttribute],
) -> Result<TaskInfo, Error> {
    self.client
        .http_client
        .request::<(), Vec<FilterableAttribute>, TaskInfo>(
            &format!(...),
            Method::Put {
                query: (),
                body: filterable_attributes.to_vec(),
            },
            202,
        )
        .await
}

This would allow callers to retain ownership of their configurations.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e90a3c2 and b926f13.

📒 Files selected for processing (3)
  • .code-samples.meilisearch.yaml (1 hunks)
  • src/documents.rs (1 hunks)
  • src/settings.rs (6 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/settings.rs (1)
src/indexes.rs (13)
  • client (186-188)
  • client (232-234)
  • client (320-322)
  • client (376-378)
  • client (428-430)
  • client (473-475)
  • client (522-525)
  • client (556-558)
  • client (634-636)
  • client (700-702)
  • client (970-972)
  • client (1038-1040)
  • client (1089-1091)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: integration-tests
🔇 Additional comments (5)
.code-samples.meilisearch.yaml (1)

549-567: LGTM: Imports and mixed-syntax demonstration are correct.

The new types are properly imported and the example correctly demonstrates both legacy syntax (using .into() for string conversion) and the new settings object syntax.

src/documents.rs (1)

706-713: LGTM: Test correctly updated for new FilterableAttribute type.

The test properly imports and uses the new FilterableAttribute enum, wrapping attribute names in the Attribute variant. This correctly reflects the changes to Settings::filterable_attributes from Option<Vec<String>> to Option<Vec<FilterableAttribute>>.

src/settings.rs (3)

67-114: LGTM: Well-structured types for mixed-syntax filterable attributes.

The new types properly model Meilisearch v1.14's advanced filterable attributes syntax:

  • Hierarchical structure with FilterFeatureModesFilterFeaturesFilterableAttributesSettings
  • Untagged enum allows seamless JSON serialization of mixed plain strings and settings objects
  • From implementations provide ergonomic string-to-attribute conversion
  • Proper camelCase JSON mapping via serde annotations

244-399: LGTM: Backward-compatible API design with advanced method.

The changes maintain backward compatibility:

  • Existing with_filterable_attributes accepts strings and converts internally
  • New with_filterable_attributes_advanced accepts mixed FilterableAttribute items
  • Clear documentation distinguishes the two approaches

This design allows gradual adoption of the new syntax while preserving existing code.


767-799: LGTM: Dual getter methods provide both legacy and advanced access.

The addition of get_filterable_attributes_advanced alongside the existing get_filterable_attributes enables:

  • Legacy code continues using Vec<String> return type
  • New code can retrieve mixed-syntax Vec<FilterableAttribute>

Both methods query the same endpoint but deserialize to different types, maintaining backward compatibility.

@codecov
Copy link

codecov bot commented Nov 10, 2025

Codecov Report

❌ Patch coverage is 97.77778% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.42%. Comparing base (e90a3c2) to head (89f6c6b).

Files with missing lines Patch % Lines
src/settings.rs 97.72% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #730      +/-   ##
==========================================
+ Coverage   86.18%   86.42%   +0.23%     
==========================================
  Files          20       20              
  Lines        6263     6395     +132     
==========================================
+ Hits         5398     5527     +129     
- Misses        865      868       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@curquiza
Copy link
Member

@kumarUjjawal sorry, but can you resolve the git conflicts please?

@curquiza curquiza added the enhancement New feature or request label Nov 21, 2025
@kumarUjjawal
Copy link
Contributor Author

@kumarUjjawal sorry, but can you resolve the git conflicts please?

Yeah, I will resolve it soon.

@kumarUjjawal
Copy link
Contributor Author

@curquiza what's this issue with code coverage?

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/settings.rs (2)

67-93: Consider enhancing documentation for new public types.

The new public types FilterFeatureModes, FilterFeatures, and FilterableAttributesSettings have minimal documentation. Since these are part of the public API for the v1.14 filterable attributes feature, consider adding:

  • Brief descriptions of each field's purpose
  • Example usage showing how to construct these types
  • Links to relevant Meilisearch documentation

This will improve discoverability and reduce confusion for SDK users.


795-813: Consider adding usage guidance in documentation.

The implementation is correct, but the doc comment could clarify when to use get_filterable_attributes_advanced versus get_filterable_attributes. Consider adding:

  • A note that this method returns the full mixed-syntax representation
  • When users should prefer this over the simpler string-based method
  • An example showing the expected return format
.code-samples.meilisearch.yaml (1)

573-592: LGTM! Clear demonstration of mixed-syntax feature.

The code sample effectively demonstrates the new v1.14 filterable attributes feature:

  • Imports all necessary types
  • Shows legacy syntax via "author".into()
  • Shows advanced syntax with FilterableAttribute::Settings
  • Includes realistic feature flags (facetSearch, equality filter only)

Consider adding a brief comment above line 581 explaining that arrays can contain any mix of strings and settings objects, to reinforce the "mixed syntax" concept for documentation readers.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1bd536 and afabcf1.

📒 Files selected for processing (3)
  • .code-samples.meilisearch.yaml (1 hunks)
  • src/documents.rs (1 hunks)
  • src/settings.rs (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/documents.rs
🧰 Additional context used
🧬 Code graph analysis (1)
src/settings.rs (2)
src/client.rs (2)
  • new (54-66)
  • index (424-426)
src/request.rs (1)
  • body (49-56)
🔇 Additional comments (6)
src/settings.rs (5)

95-114: LGTM! Well-designed enum with convenient conversions.

The untagged FilterableAttribute enum correctly models the mixed-syntax API. The structural difference between a plain String and FilterableAttributesSettings ensures serde will deserialize correctly without ambiguity. The From implementations provide ergonomic conversions.


387-413: LGTM! Excellent backward compatibility strategy.

The refactored with_filterable_attributes maintains API compatibility by wrapping strings in FilterableAttribute::Attribute, while the new with_filterable_attributes_advanced provides direct access to the mixed-syntax feature. The inline comment on line 392 clearly documents the intent.


1604-1647: LGTM! Consistent backward-compatible implementation.

Both methods correctly handle the new FilterableAttribute type. The updated set_filterable_attributes maintains API compatibility by wrapping string inputs, while set_filterable_attributes_advanced provides direct access to the mixed-syntax feature. The approach is consistent with the builder methods.


2921-2921: LGTM! Necessary test imports.

The additional to_string import is required for the new test that validates request body serialization.


2923-3027: LGTM! Comprehensive test coverage for advanced filterable attributes.

The three new tests effectively cover:

  • Builder pattern with mixed-syntax attributes
  • Request body serialization (ensuring the JSON format matches expectations)
  • Response deserialization (ensuring mixed responses are parsed correctly)

The use of mockito for HTTP-level testing is appropriate and allows precise control over request/response validation.

.code-samples.meilisearch.yaml (1)

594-598: LGTM! Correct method invocation.

The call to set_filterable_attributes_advanced(filterable_attributes) correctly passes ownership of the vector, matching the method signature that expects impl IntoIterator<Item = FilterableAttribute>. The previous issue with passing a reference has been resolved.

Comment on lines +259 to +262
///
/// Supports both plain attribute names and settings objects.
#[serde(skip_serializing_if = "Option::is_none")]
pub filterable_attributes: Option<Vec<String>>,
pub filterable_attributes: Option<Vec<FilterableAttribute>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

Verify migration path for breaking change to filterable_attributes field.

The type change from Option<Vec<String>> to Option<Vec<FilterableAttribute>> is a breaking change for code that directly accesses Settings.filterable_attributes. While the builder methods maintain backward compatibility, users who construct Settings via struct literals or access the field directly will need to update their code.

Consider:

  • Documenting this breaking change in the changelog/migration guide
  • Verifying that the most common usage patterns (via builder methods) remain unaffected

Run the following script to identify potential usage patterns in the codebase:


🏁 Script executed:

#!/bin/bash
# Find direct field access or struct construction patterns
rg -nP --type=rust -C3 'Settings\s*\{.*filterable_attributes' -g '!src/settings.rs'
rg -nP --type=rust -C3 '\.filterable_attributes\s*=' -g '!src/settings.rs'

Length of output: 0



---

🏁 Script executed:

```shell
#!/bin/bash
# Broader search for filterable_attributes usage (any pattern)
echo "=== General usage of filterable_attributes ==="
rg -nP --type=rust 'filterable_attributes' -g '!src/settings.rs' | head -20

echo -e "\n=== Builder method patterns ==="
rg -nP --type=rust 'with_filterable_attributes|set_filterable_attributes' -C2

echo -e "\n=== Check for FilterableAttribute type definition ==="
rg -nP --type=rust 'struct FilterableAttribute|enum FilterableAttribute|type FilterableAttribute'

echo -e "\n=== Check settings.rs for builder methods ==="
rg -nP --type=rust -A5 'fn.*filterable_attributes' src/settings.rs

Length of output: 11128


Breaking change confirmed: direct field access to filterable_attributes will require updates.

Direct field access exists in the codebase (e.g., documents.rs lines 754, 760 access filterable_attributes directly). Code that constructs Settings via struct literals or directly accesses the field must be updated to work with Vec<FilterableAttribute> instead of Vec<String>.

The builder methods (with_filterable_attributes(), set_filterable_attributes()) maintain backward compatibility and continue accepting strings, so most typical usage patterns are unaffected. However, any code iterating over the field or relying on String methods will break. Consider documenting this as a breaking change in the migration guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v1.14] Filterable attributes settings opt-out

2 participants